<?php
require_once("database.php");
class xl_quan_tri extends database
{
	function danh_sach($vi_tri, $so_luong)
	{
		$vi_tri = intval($vi_tri);
		$so_luong = intval($so_luong);
		$sql = "select * from quan_tri limit $vi_tri, $so_luong";
		$this->setQuery($sql);
		return $this->loadAllRow();
	}
	function so_luong()
	{
		$sql = "select count(*) from quan_tri";
		$this->setQuery($sql);
		return $this->loadResult();
	}
	function xem($ma)
	{
		$ma = intval($ma);

		$sql = "select * from quan_tri where ma = '$ma'";
		$this->setQuery($sql);
		return $this->loadRow();
	}
	
	function dang_nhap($ten_dang_nhap, $mat_khau)
	{
		$ten_dang_nhap = stripslashes($ten_dang_nhap);
		$ten_dang_nhap = addslashes($ten_dang_nhap);
		
		$mat_khau = stripslashes($mat_khau);
		$mat_khau = addslashes($mat_khau);
		
		$mat_khau = md5($mat_khau);
		$sql = "select * from quan_tri where ten_dang_nhap = '$ten_dang_nhap' and mat_khau = '$mat_khau' ";
		$this->setQuery($sql);
		return $this->loadRow();
	}
	
	function xoa($ma)
	{
		$ma = intval($ma);

		$sql = "delete from quan_tri where ma = '$ma'";
		$this->setQuery($sql);
		return $this->query();
	}
	function them($ho_ten, $ten_dang_nhap, $mat_khau, $email, $ngay_tao, $lan_dang_nhap_cuoi, $trang_thai)
	{
		$ho_ten = addslashes($ho_ten);
		$ten_dang_nhap = addslashes($ten_dang_nhap);
		$mat_khau = addslashes($mat_khau);
		$email = addslashes($email);

		$sql = "INSERT INTO quan_tri(ho_ten,ten_dang_nhap,mat_khau,email,ngay_tao,lan_dang_nhap_cuoi,trang_thai) VALUES ('$ho_ten','$ten_dang_nhap','$mat_khau','$email','$ngay_tao','$lan_dang_nhap_cuoi','$trang_thai')";
		$this->setQuery($sql);
		return $this->query();
	}
	function cap_nhat($ma, $ho_ten, $ten_dang_nhap, $mat_khau, $email, $ngay_tao, $lan_dang_nhap_cuoi, $trang_thai)
	{
		$ma = intval($ma);
		$ho_ten = addslashes($ho_ten);
		$ten_dang_nhap = addslashes($ten_dang_nhap);
		$mat_khau = addslashes($mat_khau);
		$email = addslashes($email);

		$sql ="UPDATE quan_tri SET ho_ten= '$ho_ten', ten_dang_nhap= '$ten_dang_nhap', mat_khau= '$mat_khau', email= '$email', ngay_tao= '$ngay_tao', lan_dang_nhap_cuoi= '$lan_dang_nhap_cuoi', trang_thai= '$trang_thai' WHERE ma = '$ma'";
		$this->setQuery($sql);
		return $this->query();
	}
	function tim_kiem ($tu_khoa)
	{
		$sql = "select * from quan_tri where	$ho_ten like %tu_khoa% or 	$ten_dang_nhap like %tu_khoa% or 	$mat_khau like %tu_khoa% or 	$email like %tu_khoa%"; 
		$this->setQuery($sql);
		return $this->loadAllRow();	
	}
 }
?>